//
//  HACancelAccountPopView.m
//  HA
//
//  Created by sy on 2023/12/17.
//

#import "HACancelAccountPopView.h"

@interface HACancelAccountPopView () <UITextFieldDelegate>

/***/
@property (nonatomic, strong)  UITextField *pwdTextField;

@end

@implementation HACancelAccountPopView

-(instancetype)init {
    if (self = [super init]) {

        [self layoutViews];
    }
    return self;

}

-(void)didTapBackgroundView:(UITapGestureRecognizer *)sender {
    [self endEditing:YES];
}

-(void)buttomrightButtonClick {
    [self endEditing:YES];
    
    if ([NSString isEmptyString:self.pwdTextField.text]) {
        [MBProgressHUD showError:@"等输入登录密码"];
        return;
    }
    
    if (self.HACancelAccountPopViewSureBlock) {
        self.HACancelAccountPopViewSureBlock(self.pwdTextField.text);
    }
    
    [self dismiss];
}

-(void)buttomleftButtonClick {
    
    [self endEditing:YES];
    
    [self dismiss];
    
}

-(void)layoutViews {
    
    self.frame = CGRectMake(0, 0, kUIScreen_w, kUIScreen_h);
    [self addSubview:self.backgroundView];
    
    CGFloat alertViewW = 248;
    CGFloat alertViewH = 188;
    CGFloat alertViewX = (kUIScreen_w-alertViewW)*0.5;
    CGFloat alertViewY = (kUIScreen_h-alertViewH)*0.5;
    self.alertViewY = alertViewY;
    self.alertView.frame = CGRectMake(alertViewX, alertViewY, alertViewW, alertViewH);
    [self addSubview: self.alertView];
    self.alertView.layer.cornerRadius = 5;
    self.alertView.layer.masksToBounds = YES;
    
    UILabel *conLabel = [UILabel ha_NLabelWithFont:14 textColor:@"#333333" text:@"确定注销账号吗？" alignment:1];
    [self.alertView addSubview:conLabel];
    [conLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(24);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
    }];
    
    UIView *line1 = [UIView ha_createView];
    line1.backgroundColor = [UIColor colorWithHexString:@"#E3E3E3"];
    [self.alertView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.top.mas_equalTo(112);
        make.height.equalTo(@0.8);
    }];
    
    UITextField *pwdTextField = [[UITextField alloc]init];
    self.pwdTextField = pwdTextField;
    pwdTextField.textColor = [UIColor colorWithHexString:@"#333333"];
    pwdTextField.font = [UIFont systemFontOfSize:13];
    pwdTextField.placeholder = @"请输入登录密码";
    pwdTextField.secureTextEntry = YES;
    pwdTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    pwdTextField.delegate = self;
    [self.alertView addSubview:pwdTextField];
    [pwdTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(line1.mas_top).offset(-8);
        make.left.equalTo(line1);
        make.right.equalTo(line1);
        make.height.equalTo(@32);
    }];
    
    UIButton *leftButton = [[UIButton alloc]init];
    leftButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [leftButton setTitle:@"取消" forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(buttomleftButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setTitleColor:[UIColor colorWithHexString:@"#303133"] forState:0];
    [self.alertView addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(-55);
        make.bottom.mas_equalTo(-10);
        make.width.mas_offset(60);
        make.height.mas_offset(40);
    }];
    
    UIButton *rightButton = [[UIButton alloc]init];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [rightButton setTitle:@"确定" forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(buttomrightButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setTitleColor:[UIColor colorWithHexString:@"#303133"] forState:0];
    [self.alertView addSubview:rightButton];
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(55);
        make.bottom.mas_equalTo(-10);
        make.width.mas_offset(60);
        make.height.mas_offset(40);
    }];


}



@end
